/*
 * Academic License - for use in teaching, academic research, and meeting
 * course requirements at degree granting institutions only.  Not for
 * government, commercial, or other organizational use.
 * File: wiener_ADAPTIVE_NE.c
 *
 * MATLAB Coder version            : 3.4
 * C/C++ source code generated on  : 06-Oct-2017 12:42:28
 */

/* Include Files */
#include "rt_nonfinite.h"
#include "wiener_ADAPTIVE_NE.h"
#include "wiener_ADAPTIVE_NE_emxutil.h"
#include "power.h"
#include "abs.h"
#include "sqrt.h"
#include "rdivide.h"
#include "fft.h"
#include "wiener_ADAPTIVE_NE_rtwutil.h"
#include "wiener_ADAPTIVE_NE_data.h"

/* Type Definitions */
#ifndef struct_emxArray_real32_T_1x512
#define struct_emxArray_real32_T_1x512

struct emxArray_real32_T_1x512
{
  float data[512];
  int size[2];
};

#endif                                 /*struct_emxArray_real32_T_1x512*/

#ifndef typedef_emxArray_real32_T_1x512
#define typedef_emxArray_real32_T_1x512

typedef struct emxArray_real32_T_1x512 emxArray_real32_T_1x512;

#endif                                 /*typedef_emxArray_real32_T_1x512*/

/* Variable Definitions */
static float dec_count;
static float chunk_count;
static float temp;
static float buffer[400];
static float j;
static float noise_count;
static float count;
static float first_count;
static emxArray_real32_T_1x512 noise_ps;
static boolean_T noise_ps_not_empty;
static emxArray_real32_T *noise_ps_temp;
static boolean_T noise_ps_temp_not_empty;
static emxArray_real32_T_1x512 G_prev;
static boolean_T G_prev_not_empty;
static emxArray_real32_T_1x512 posteri_prev;
static boolean_T posteri_prev_not_empty;
static float overlap[200];
static float overlap_spl[200];
static float update;
static float SPL;
static float flag;

/* Function Declarations */
static float rt_roundf_snf(float u);

/* Function Definitions */

/*
 * Arguments    : float u
 * Return Type  : float
 */
static float rt_roundf_snf(float u)
{
  float y;
  if ((float)fabs(u) < 8.388608E+6F) {
    if (u >= 0.5F) {
      y = (float)floor(u + 0.5F);
    } else if (u > -0.5F) {
      y = u * 0.0F;
    } else {
      y = (float)ceil(u - 0.5F);
    }
  } else {
    y = u;
  }

  return y;
}

/*
 * Buffer to store the frames
 * Arguments    : const float frame_in[200]
 *                float spl_threshold
 *                float Srate
 *                float label
 *                float dl
 *                float out[200]
 * Return Type  : void
 */
void wiener_ADAPTIVE_NE(const float frame_in[200], float spl_threshold, float
  Srate, float label, float dl, float out[200])
{
  int nBd2;
  float fv1[400];
  double d0;
  float U2;
  static const double a[400] = { 0.079999998211860657, 0.080057032406330109,
    0.080228120088577271, 0.080513216555118561, 0.0809122622013092,
    0.08142513781785965, 0.082051731646060944, 0.082791887223720551,
    0.083645418286323547, 0.084612108767032623, 0.085691727697849274,
    0.086883999407291412, 0.088188633322715759, 0.089605309069156647,
    0.091133661568164825, 0.092773325741291046, 0.094523891806602478,
    0.0963849201798439, 0.098355956375598907, 0.1004365086555481,
    0.10262606292963028, 0.10492406785488129, 0.10732996463775635,
    0.10984314978122711, 0.11246300488710403, 0.11518887430429459,
    0.11802008748054504, 0.1209559440612793, 0.12399570643901825,
    0.12713862955570221, 0.1303839236497879, 0.13373079895973206,
    0.13717842102050781, 0.14072592556476593, 0.14437244832515717,
    0.1481170654296875, 0.15195886790752411, 0.15589688718318939,
    0.15993016958236694, 0.16405768692493439, 0.16827842593193054,
    0.17259134352207184, 0.17699536681175232, 0.18148940801620483,
    0.18607234954833984, 0.19074305891990662, 0.19550037384033203,
    0.20034310221672058, 0.20527006685733795, 0.21028004586696625,
    0.215371772646904, 0.22054401040077209, 0.2257954478263855,
    0.23112481832504272, 0.23653076589107513, 0.24201197922229767,
    0.2475670725107193, 0.25319468975067139, 0.25889343023300171,
    0.26466187834739685, 0.27049857378005981, 0.27640214562416077,
    0.28237104415893555, 0.28840383887290955, 0.29449903964996338,
    0.30065509676933289, 0.30687052011489868, 0.31314373016357422,
    0.31947323679924011, 0.32585740089416504, 0.33229464292526245,
    0.33878341317176819, 0.34532210230827332, 0.35190904140472412,
    0.35854262113571167, 0.36522120237350464, 0.37194311618804932,
    0.37870672345161438, 0.38551032543182373, 0.39235222339630127,
    0.3992307186126709, 0.40614414215087891, 0.41309076547622681,
    0.42006886005401611, 0.42707666754722595, 0.43411248922348022,
    0.44117459654808044, 0.44826117157936096, 0.45537051558494568,
    0.46250084042549133, 0.46965038776397705, 0.47681736946105957,
    0.484000027179718, 0.49119654297828674, 0.49840518832206726,
    0.50562417507171631, 0.51285165548324585, 0.520085871219635,
    0.52732497453689575, 0.53456729650497437, 0.541810929775238,
    0.54905414581298828, 0.55629509687423706, 0.56353199481964111,
    0.57076305150985718, 0.577986478805542, 0.58520054817199707,
    0.5924033522605896, 0.59959316253662109, 0.60676819086074829,
    0.61392670869827271, 0.6210668683052063, 0.62818688154220581,
    0.63528507947921753, 0.64235961437225342, 0.64940881729125977,
    0.65643084049224854, 0.663424015045166, 0.670386552810669,
    0.67731678485870361, 0.68421298265457153, 0.69107341766357422,
    0.69789636135101318, 0.70468020439147949, 0.71142315864562988,
    0.71812361478805542, 0.72477990388870239, 0.73139035701751709,
    0.73795336484909058, 0.74446731805801392, 0.75093048810958862,
    0.75734144449234009, 0.76369845867156982, 0.76999998092651367,
    0.77624452114105225, 0.78243046998977661, 0.78855627775192261,
    0.79462045431137085, 0.800621509552002, 0.80655789375305176,
    0.81242823600769043, 0.81823098659515381, 0.82396471500396729,
    0.8296281099319458, 0.8352196216583252, 0.84073793888092041,
    0.84618169069290161, 0.851549506187439, 0.85684007406234741,
    0.86205208301544189, 0.86718422174453735, 0.87223523855209351,
    0.87720388174057007, 0.882088840007782, 0.88688904047012329,
    0.89160317182540894, 0.896230161190033, 0.90076881647109985,
    0.90521794557571411, 0.90957659482955933, 0.91384351253509521,
    0.91801780462265015, 0.92209833860397339, 0.92608410120010376,
    0.92997413873672485, 0.93376743793487549, 0.937463104724884,
    0.94106024503707886, 0.94455790519714355, 0.94795525074005127,
    0.95125144720077515, 0.95444566011428833, 0.95753711462020874,
    0.9605250358581543, 0.96340864896774292, 0.96618729829788208,
    0.9688602089881897, 0.97142684459686279, 0.97388643026351929,
    0.9762384295463562, 0.97848230600357056, 0.98061740398406982,
    0.98264330625534058, 0.98455935716629028, 0.98636519908905029,
    0.98806041479110718, 0.989644467830658, 0.991117000579834,
    0.99247771501541138, 0.99372619390487671, 0.99486219882965088,
    0.99588537216186523, 0.99679553508758545, 0.99759238958358765,
    0.9982757568359375, 0.99884551763534546, 0.9993014931678772,
    0.99964356422424316, 0.99987167119979858, 0.99998575448989868,
    0.99998575448989868, 0.99987167119979858, 0.99964356422424316,
    0.9993014931678772, 0.99884551763534546, 0.9982757568359375,
    0.99759238958358765, 0.99679553508758545, 0.99588537216186523,
    0.99486219882965088, 0.99372619390487671, 0.99247771501541138,
    0.991117000579834, 0.989644467830658, 0.98806041479110718,
    0.98636519908905029, 0.98455935716629028, 0.98264330625534058,
    0.98061740398406982, 0.97848230600357056, 0.9762384295463562,
    0.97388643026351929, 0.97142684459686279, 0.9688602089881897,
    0.96618729829788208, 0.96340864896774292, 0.9605250358581543,
    0.95753711462020874, 0.95444566011428833, 0.95125144720077515,
    0.94795525074005127, 0.94455790519714355, 0.94106024503707886,
    0.937463104724884, 0.93376743793487549, 0.92997413873672485,
    0.92608410120010376, 0.92209833860397339, 0.91801780462265015,
    0.91384351253509521, 0.90957659482955933, 0.90521794557571411,
    0.90076881647109985, 0.896230161190033, 0.89160317182540894,
    0.88688904047012329, 0.882088840007782, 0.87720388174057007,
    0.87223523855209351, 0.86718422174453735, 0.86205208301544189,
    0.85684007406234741, 0.851549506187439, 0.84618169069290161,
    0.84073793888092041, 0.8352196216583252, 0.8296281099319458,
    0.82396471500396729, 0.81823098659515381, 0.81242823600769043,
    0.80655789375305176, 0.800621509552002, 0.79462045431137085,
    0.78855627775192261, 0.78243046998977661, 0.77624452114105225,
    0.76999998092651367, 0.76369845867156982, 0.75734144449234009,
    0.75093048810958862, 0.74446731805801392, 0.73795336484909058,
    0.73139035701751709, 0.72477990388870239, 0.71812361478805542,
    0.71142315864562988, 0.70468020439147949, 0.69789636135101318,
    0.69107341766357422, 0.68421298265457153, 0.67731678485870361,
    0.670386552810669, 0.663424015045166, 0.65643084049224854,
    0.64940881729125977, 0.64235961437225342, 0.63528507947921753,
    0.62818688154220581, 0.6210668683052063, 0.61392670869827271,
    0.60676819086074829, 0.59959316253662109, 0.5924033522605896,
    0.58520054817199707, 0.577986478805542, 0.57076305150985718,
    0.56353199481964111, 0.55629509687423706, 0.54905414581298828,
    0.541810929775238, 0.53456729650497437, 0.52732497453689575,
    0.520085871219635, 0.51285165548324585, 0.50562417507171631,
    0.49840518832206726, 0.49119654297828674, 0.484000027179718,
    0.47681736946105957, 0.46965038776397705, 0.46250084042549133,
    0.45537051558494568, 0.44826117157936096, 0.44117459654808044,
    0.43411248922348022, 0.42707666754722595, 0.42006886005401611,
    0.41309076547622681, 0.40614414215087891, 0.3992307186126709,
    0.39235222339630127, 0.38551032543182373, 0.37870672345161438,
    0.37194311618804932, 0.36522120237350464, 0.35854262113571167,
    0.35190904140472412, 0.34532210230827332, 0.33878341317176819,
    0.33229464292526245, 0.32585740089416504, 0.31947323679924011,
    0.31314373016357422, 0.30687052011489868, 0.30065509676933289,
    0.29449903964996338, 0.28840383887290955, 0.28237104415893555,
    0.27640214562416077, 0.27049857378005981, 0.26466187834739685,
    0.25889343023300171, 0.25319468975067139, 0.2475670725107193,
    0.24201197922229767, 0.23653076589107513, 0.23112481832504272,
    0.2257954478263855, 0.22054401040077209, 0.215371772646904,
    0.21028004586696625, 0.20527006685733795, 0.20034310221672058,
    0.19550037384033203, 0.19074305891990662, 0.18607234954833984,
    0.18148940801620483, 0.17699536681175232, 0.17259134352207184,
    0.16827842593193054, 0.16405768692493439, 0.15993016958236694,
    0.15589688718318939, 0.15195886790752411, 0.1481170654296875,
    0.14437244832515717, 0.14072592556476593, 0.13717842102050781,
    0.13373079895973206, 0.1303839236497879, 0.12713862955570221,
    0.12399570643901825, 0.1209559440612793, 0.11802008748054504,
    0.11518887430429459, 0.11246300488710403, 0.10984314978122711,
    0.10732996463775635, 0.10492406785488129, 0.10262606292963028,
    0.1004365086555481, 0.098355956375598907, 0.0963849201798439,
    0.094523891806602478, 0.092773325741291046, 0.091133661568164825,
    0.089605309069156647, 0.088188633322715759, 0.086883999407291412,
    0.085691727697849274, 0.084612108767032623, 0.083645418286323547,
    0.082791887223720551, 0.082051731646060944, 0.08142513781785965,
    0.0809122622013092, 0.080513216555118561, 0.080228120088577271,
    0.080057032406330109, 0.079999998211860657 };

  static const double b[400] = { 0.079999998211860657, 0.080057032406330109,
    0.080228120088577271, 0.080513216555118561, 0.0809122622013092,
    0.08142513781785965, 0.082051731646060944, 0.082791887223720551,
    0.083645418286323547, 0.084612108767032623, 0.085691727697849274,
    0.086883999407291412, 0.088188633322715759, 0.089605309069156647,
    0.091133661568164825, 0.092773325741291046, 0.094523891806602478,
    0.0963849201798439, 0.098355956375598907, 0.1004365086555481,
    0.10262606292963028, 0.10492406785488129, 0.10732996463775635,
    0.10984314978122711, 0.11246300488710403, 0.11518887430429459,
    0.11802008748054504, 0.1209559440612793, 0.12399570643901825,
    0.12713862955570221, 0.1303839236497879, 0.13373079895973206,
    0.13717842102050781, 0.14072592556476593, 0.14437244832515717,
    0.1481170654296875, 0.15195886790752411, 0.15589688718318939,
    0.15993016958236694, 0.16405768692493439, 0.16827842593193054,
    0.17259134352207184, 0.17699536681175232, 0.18148940801620483,
    0.18607234954833984, 0.19074305891990662, 0.19550037384033203,
    0.20034310221672058, 0.20527006685733795, 0.21028004586696625,
    0.215371772646904, 0.22054401040077209, 0.2257954478263855,
    0.23112481832504272, 0.23653076589107513, 0.24201197922229767,
    0.2475670725107193, 0.25319468975067139, 0.25889343023300171,
    0.26466187834739685, 0.27049857378005981, 0.27640214562416077,
    0.28237104415893555, 0.28840383887290955, 0.29449903964996338,
    0.30065509676933289, 0.30687052011489868, 0.31314373016357422,
    0.31947323679924011, 0.32585740089416504, 0.33229464292526245,
    0.33878341317176819, 0.34532210230827332, 0.35190904140472412,
    0.35854262113571167, 0.36522120237350464, 0.37194311618804932,
    0.37870672345161438, 0.38551032543182373, 0.39235222339630127,
    0.3992307186126709, 0.40614414215087891, 0.41309076547622681,
    0.42006886005401611, 0.42707666754722595, 0.43411248922348022,
    0.44117459654808044, 0.44826117157936096, 0.45537051558494568,
    0.46250084042549133, 0.46965038776397705, 0.47681736946105957,
    0.484000027179718, 0.49119654297828674, 0.49840518832206726,
    0.50562417507171631, 0.51285165548324585, 0.520085871219635,
    0.52732497453689575, 0.53456729650497437, 0.541810929775238,
    0.54905414581298828, 0.55629509687423706, 0.56353199481964111,
    0.57076305150985718, 0.577986478805542, 0.58520054817199707,
    0.5924033522605896, 0.59959316253662109, 0.60676819086074829,
    0.61392670869827271, 0.6210668683052063, 0.62818688154220581,
    0.63528507947921753, 0.64235961437225342, 0.64940881729125977,
    0.65643084049224854, 0.663424015045166, 0.670386552810669,
    0.67731678485870361, 0.68421298265457153, 0.69107341766357422,
    0.69789636135101318, 0.70468020439147949, 0.71142315864562988,
    0.71812361478805542, 0.72477990388870239, 0.73139035701751709,
    0.73795336484909058, 0.74446731805801392, 0.75093048810958862,
    0.75734144449234009, 0.76369845867156982, 0.76999998092651367,
    0.77624452114105225, 0.78243046998977661, 0.78855627775192261,
    0.79462045431137085, 0.800621509552002, 0.80655789375305176,
    0.81242823600769043, 0.81823098659515381, 0.82396471500396729,
    0.8296281099319458, 0.8352196216583252, 0.84073793888092041,
    0.84618169069290161, 0.851549506187439, 0.85684007406234741,
    0.86205208301544189, 0.86718422174453735, 0.87223523855209351,
    0.87720388174057007, 0.882088840007782, 0.88688904047012329,
    0.89160317182540894, 0.896230161190033, 0.90076881647109985,
    0.90521794557571411, 0.90957659482955933, 0.91384351253509521,
    0.91801780462265015, 0.92209833860397339, 0.92608410120010376,
    0.92997413873672485, 0.93376743793487549, 0.937463104724884,
    0.94106024503707886, 0.94455790519714355, 0.94795525074005127,
    0.95125144720077515, 0.95444566011428833, 0.95753711462020874,
    0.9605250358581543, 0.96340864896774292, 0.96618729829788208,
    0.9688602089881897, 0.97142684459686279, 0.97388643026351929,
    0.9762384295463562, 0.97848230600357056, 0.98061740398406982,
    0.98264330625534058, 0.98455935716629028, 0.98636519908905029,
    0.98806041479110718, 0.989644467830658, 0.991117000579834,
    0.99247771501541138, 0.99372619390487671, 0.99486219882965088,
    0.99588537216186523, 0.99679553508758545, 0.99759238958358765,
    0.9982757568359375, 0.99884551763534546, 0.9993014931678772,
    0.99964356422424316, 0.99987167119979858, 0.99998575448989868,
    0.99998575448989868, 0.99987167119979858, 0.99964356422424316,
    0.9993014931678772, 0.99884551763534546, 0.9982757568359375,
    0.99759238958358765, 0.99679553508758545, 0.99588537216186523,
    0.99486219882965088, 0.99372619390487671, 0.99247771501541138,
    0.991117000579834, 0.989644467830658, 0.98806041479110718,
    0.98636519908905029, 0.98455935716629028, 0.98264330625534058,
    0.98061740398406982, 0.97848230600357056, 0.9762384295463562,
    0.97388643026351929, 0.97142684459686279, 0.9688602089881897,
    0.96618729829788208, 0.96340864896774292, 0.9605250358581543,
    0.95753711462020874, 0.95444566011428833, 0.95125144720077515,
    0.94795525074005127, 0.94455790519714355, 0.94106024503707886,
    0.937463104724884, 0.93376743793487549, 0.92997413873672485,
    0.92608410120010376, 0.92209833860397339, 0.91801780462265015,
    0.91384351253509521, 0.90957659482955933, 0.90521794557571411,
    0.90076881647109985, 0.896230161190033, 0.89160317182540894,
    0.88688904047012329, 0.882088840007782, 0.87720388174057007,
    0.87223523855209351, 0.86718422174453735, 0.86205208301544189,
    0.85684007406234741, 0.851549506187439, 0.84618169069290161,
    0.84073793888092041, 0.8352196216583252, 0.8296281099319458,
    0.82396471500396729, 0.81823098659515381, 0.81242823600769043,
    0.80655789375305176, 0.800621509552002, 0.79462045431137085,
    0.78855627775192261, 0.78243046998977661, 0.77624452114105225,
    0.76999998092651367, 0.76369845867156982, 0.75734144449234009,
    0.75093048810958862, 0.74446731805801392, 0.73795336484909058,
    0.73139035701751709, 0.72477990388870239, 0.71812361478805542,
    0.71142315864562988, 0.70468020439147949, 0.69789636135101318,
    0.69107341766357422, 0.68421298265457153, 0.67731678485870361,
    0.670386552810669, 0.663424015045166, 0.65643084049224854,
    0.64940881729125977, 0.64235961437225342, 0.63528507947921753,
    0.62818688154220581, 0.6210668683052063, 0.61392670869827271,
    0.60676819086074829, 0.59959316253662109, 0.5924033522605896,
    0.58520054817199707, 0.577986478805542, 0.57076305150985718,
    0.56353199481964111, 0.55629509687423706, 0.54905414581298828,
    0.541810929775238, 0.53456729650497437, 0.52732497453689575,
    0.520085871219635, 0.51285165548324585, 0.50562417507171631,
    0.49840518832206726, 0.49119654297828674, 0.484000027179718,
    0.47681736946105957, 0.46965038776397705, 0.46250084042549133,
    0.45537051558494568, 0.44826117157936096, 0.44117459654808044,
    0.43411248922348022, 0.42707666754722595, 0.42006886005401611,
    0.41309076547622681, 0.40614414215087891, 0.3992307186126709,
    0.39235222339630127, 0.38551032543182373, 0.37870672345161438,
    0.37194311618804932, 0.36522120237350464, 0.35854262113571167,
    0.35190904140472412, 0.34532210230827332, 0.33878341317176819,
    0.33229464292526245, 0.32585740089416504, 0.31947323679924011,
    0.31314373016357422, 0.30687052011489868, 0.30065509676933289,
    0.29449903964996338, 0.28840383887290955, 0.28237104415893555,
    0.27640214562416077, 0.27049857378005981, 0.26466187834739685,
    0.25889343023300171, 0.25319468975067139, 0.2475670725107193,
    0.24201197922229767, 0.23653076589107513, 0.23112481832504272,
    0.2257954478263855, 0.22054401040077209, 0.215371772646904,
    0.21028004586696625, 0.20527006685733795, 0.20034310221672058,
    0.19550037384033203, 0.19074305891990662, 0.18607234954833984,
    0.18148940801620483, 0.17699536681175232, 0.17259134352207184,
    0.16827842593193054, 0.16405768692493439, 0.15993016958236694,
    0.15589688718318939, 0.15195886790752411, 0.1481170654296875,
    0.14437244832515717, 0.14072592556476593, 0.13717842102050781,
    0.13373079895973206, 0.1303839236497879, 0.12713862955570221,
    0.12399570643901825, 0.1209559440612793, 0.11802008748054504,
    0.11518887430429459, 0.11246300488710403, 0.10984314978122711,
    0.10732996463775635, 0.10492406785488129, 0.10262606292963028,
    0.1004365086555481, 0.098355956375598907, 0.0963849201798439,
    0.094523891806602478, 0.092773325741291046, 0.091133661568164825,
    0.089605309069156647, 0.088188633322715759, 0.086883999407291412,
    0.085691727697849274, 0.084612108767032623, 0.083645418286323547,
    0.082791887223720551, 0.082051731646060944, 0.08142513781785965,
    0.0809122622013092, 0.080513216555118561, 0.080228120088577271,
    0.080057032406330109, 0.079999998211860657 };

  creal32_T fcv0[400];
  static const float fv2[400] = { 0.08F, 0.0800570324F, 0.0802281201F,
    0.0805132166F, 0.0809122622F, 0.0814251378F, 0.0820517316F, 0.0827918872F,
    0.0836454183F, 0.0846121088F, 0.0856917277F, 0.086884F, 0.0881886333F,
    0.0896053091F, 0.0911336616F, 0.0927733257F, 0.0945238918F, 0.0963849202F,
    0.0983559564F, 0.100436509F, 0.102626063F, 0.104924068F, 0.107329965F,
    0.10984315F, 0.112463005F, 0.115188874F, 0.118020087F, 0.120955944F,
    0.123995706F, 0.12713863F, 0.130383924F, 0.133730799F, 0.137178421F,
    0.140725926F, 0.144372448F, 0.148117065F, 0.151958868F, 0.155896887F,
    0.15993017F, 0.164057687F, 0.168278426F, 0.172591344F, 0.176995367F,
    0.181489408F, 0.18607235F, 0.190743059F, 0.195500374F, 0.200343102F,
    0.205270067F, 0.210280046F, 0.215371773F, 0.22054401F, 0.225795448F,
    0.231124818F, 0.236530766F, 0.242011979F, 0.247567073F, 0.25319469F,
    0.25889343F, 0.264661878F, 0.270498574F, 0.276402146F, 0.282371044F,
    0.288403839F, 0.29449904F, 0.300655097F, 0.30687052F, 0.31314373F,
    0.319473237F, 0.325857401F, 0.332294643F, 0.338783413F, 0.345322102F,
    0.351909041F, 0.358542621F, 0.365221202F, 0.371943116F, 0.378706723F,
    0.385510325F, 0.392352223F, 0.399230719F, 0.406144142F, 0.413090765F,
    0.42006886F, 0.427076668F, 0.434112489F, 0.441174597F, 0.448261172F,
    0.455370516F, 0.46250084F, 0.469650388F, 0.476817369F, 0.484000027F,
    0.491196543F, 0.498405188F, 0.505624175F, 0.512851655F, 0.520085871F,
    0.527325F, 0.534567297F, 0.54181093F, 0.549054146F, 0.556295097F, 0.563532F,
    0.570763052F, 0.577986479F, 0.585200548F, 0.592403352F, 0.599593163F,
    0.606768191F, 0.613926709F, 0.621066868F, 0.628186882F, 0.635285079F,
    0.642359614F, 0.649408817F, 0.65643084F, 0.663424F, 0.670386553F,
    0.677316785F, 0.684213F, 0.691073418F, 0.697896361F, 0.704680204F,
    0.711423159F, 0.718123615F, 0.724779904F, 0.731390357F, 0.737953365F,
    0.744467318F, 0.750930488F, 0.757341444F, 0.763698459F, 0.77F, 0.776244521F,
    0.78243047F, 0.788556278F, 0.794620454F, 0.80062151F, 0.806557894F,
    0.812428236F, 0.818231F, 0.823964715F, 0.82962811F, 0.835219622F,
    0.840737939F, 0.846181691F, 0.851549506F, 0.856840074F, 0.862052083F,
    0.867184222F, 0.872235239F, 0.877203882F, 0.88208884F, 0.88688904F,
    0.891603172F, 0.896230161F, 0.900768816F, 0.905217946F, 0.909576595F,
    0.913843513F, 0.918017805F, 0.922098339F, 0.926084101F, 0.929974139F,
    0.933767438F, 0.937463105F, 0.941060245F, 0.944557905F, 0.947955251F,
    0.951251447F, 0.95444566F, 0.957537115F, 0.960525036F, 0.963408649F,
    0.966187298F, 0.968860209F, 0.971426845F, 0.97388643F, 0.97623843F,
    0.978482306F, 0.980617404F, 0.982643306F, 0.984559357F, 0.986365199F,
    0.988060415F, 0.989644468F, 0.991117F, 0.992477715F, 0.993726194F,
    0.994862199F, 0.995885372F, 0.996795535F, 0.99759239F, 0.998275757F,
    0.998845518F, 0.999301493F, 0.999643564F, 0.999871671F, 0.999985754F,
    0.999985754F, 0.999871671F, 0.999643564F, 0.999301493F, 0.998845518F,
    0.998275757F, 0.99759239F, 0.996795535F, 0.995885372F, 0.994862199F,
    0.993726194F, 0.992477715F, 0.991117F, 0.989644468F, 0.988060415F,
    0.986365199F, 0.984559357F, 0.982643306F, 0.980617404F, 0.978482306F,
    0.97623843F, 0.97388643F, 0.971426845F, 0.968860209F, 0.966187298F,
    0.963408649F, 0.960525036F, 0.957537115F, 0.95444566F, 0.951251447F,
    0.947955251F, 0.944557905F, 0.941060245F, 0.937463105F, 0.933767438F,
    0.929974139F, 0.926084101F, 0.922098339F, 0.918017805F, 0.913843513F,
    0.909576595F, 0.905217946F, 0.900768816F, 0.896230161F, 0.891603172F,
    0.88688904F, 0.88208884F, 0.877203882F, 0.872235239F, 0.867184222F,
    0.862052083F, 0.856840074F, 0.851549506F, 0.846181691F, 0.840737939F,
    0.835219622F, 0.82962811F, 0.823964715F, 0.818231F, 0.812428236F,
    0.806557894F, 0.80062151F, 0.794620454F, 0.788556278F, 0.78243047F,
    0.776244521F, 0.77F, 0.763698459F, 0.757341444F, 0.750930488F, 0.744467318F,
    0.737953365F, 0.731390357F, 0.724779904F, 0.718123615F, 0.711423159F,
    0.704680204F, 0.697896361F, 0.691073418F, 0.684213F, 0.677316785F,
    0.670386553F, 0.663424F, 0.65643084F, 0.649408817F, 0.642359614F,
    0.635285079F, 0.628186882F, 0.621066868F, 0.613926709F, 0.606768191F,
    0.599593163F, 0.592403352F, 0.585200548F, 0.577986479F, 0.570763052F,
    0.563532F, 0.556295097F, 0.549054146F, 0.54181093F, 0.534567297F, 0.527325F,
    0.520085871F, 0.512851655F, 0.505624175F, 0.498405188F, 0.491196543F,
    0.484000027F, 0.476817369F, 0.469650388F, 0.46250084F, 0.455370516F,
    0.448261172F, 0.441174597F, 0.434112489F, 0.427076668F, 0.42006886F,
    0.413090765F, 0.406144142F, 0.399230719F, 0.392352223F, 0.385510325F,
    0.378706723F, 0.371943116F, 0.365221202F, 0.358542621F, 0.351909041F,
    0.345322102F, 0.338783413F, 0.332294643F, 0.325857401F, 0.319473237F,
    0.31314373F, 0.30687052F, 0.300655097F, 0.29449904F, 0.288403839F,
    0.282371044F, 0.276402146F, 0.270498574F, 0.264661878F, 0.25889343F,
    0.25319469F, 0.247567073F, 0.242011979F, 0.236530766F, 0.231124818F,
    0.225795448F, 0.22054401F, 0.215371773F, 0.210280046F, 0.205270067F,
    0.200343102F, 0.195500374F, 0.190743059F, 0.18607235F, 0.181489408F,
    0.176995367F, 0.172591344F, 0.168278426F, 0.164057687F, 0.15993017F,
    0.155896887F, 0.151958868F, 0.148117065F, 0.144372448F, 0.140725926F,
    0.137178421F, 0.133730799F, 0.130383924F, 0.12713863F, 0.123995706F,
    0.120955944F, 0.118020087F, 0.115188874F, 0.112463005F, 0.10984315F,
    0.107329965F, 0.104924068F, 0.102626063F, 0.100436509F, 0.0983559564F,
    0.0963849202F, 0.0945238918F, 0.0927733257F, 0.0911336616F, 0.0896053091F,
    0.0881886333F, 0.086884F, 0.0856917277F, 0.0846121088F, 0.0836454183F,
    0.0827918872F, 0.0820517316F, 0.0814251378F, 0.0809122622F, 0.0805132166F,
    0.0802281201F, 0.0800570324F, 0.08F };

  float fv3[400];
  float x[400];
  float twid_re;
  int k;
  creal32_T noise_fft[512];
  emxArray_real32_T *r0;
  float twid_im;
  float noisy_ps[512];
  float snr_detect;
  float posteri[512];
  int i;
  int iy;
  int b_size[2];
  float posteri_prime[512];
  float b_posteri_prime[512];
  emxArray_real32_T *wind;
  int ix;
  int ju;
  creal32_T b_y1[512];
  boolean_T tst;
  int b_j;
  static const float fv4[257] = { 0.0F, 0.0122715384F, 0.024541229F,
    0.0368072242F, 0.0490676761F, 0.0613207407F, 0.0735645667F, 0.0857973173F,
    0.0980171412F, 0.110222206F, 0.122410677F, 0.134580716F, 0.146730468F,
    0.15885815F, 0.170961902F, 0.183039889F, 0.195090324F, 0.207111388F,
    0.219101235F, 0.231058121F, 0.242980197F, 0.254865676F, 0.266712785F,
    0.27851969F, 0.290284663F, 0.302005947F, 0.313681751F, 0.32531032F,
    0.336889863F, 0.348418683F, 0.359895051F, 0.371317208F, 0.382683456F,
    0.393992066F, 0.40524134F, 0.416429579F, 0.427555084F, 0.438616246F,
    0.449611336F, 0.460538715F, 0.471396744F, 0.482183754F, 0.492898226F,
    0.50353837F, 0.514102757F, 0.524589717F, 0.534997642F, 0.545325041F,
    0.555570245F, 0.565731823F, 0.575808227F, 0.585797906F, 0.59569931F,
    0.605511F, 0.615231633F, 0.624859512F, 0.634393334F, 0.643831551F,
    0.653172851F, 0.662415802F, 0.671559F, 0.680601F, 0.689540565F, 0.698376298F,
    0.707106769F, 0.715730786F, 0.724247098F, 0.732654274F, 0.740951121F,
    0.749136388F, 0.757208824F, 0.765167236F, 0.773010433F, 0.780737221F,
    0.78834641F, 0.795836926F, 0.803207517F, 0.81045717F, 0.817584813F,
    0.824589252F, 0.831469595F, 0.838224709F, 0.84485358F, 0.851355195F,
    0.857728601F, 0.863972843F, 0.870086968F, 0.876070082F, 0.881921232F,
    0.887639642F, 0.893224299F, 0.898674488F, 0.903989315F, 0.909167945F,
    0.914209723F, 0.919113874F, 0.923879504F, 0.928506076F, 0.932992816F,
    0.937339F, 0.941544056F, 0.945607305F, 0.949528158F, 0.953306F, 0.956940353F,
    0.960430503F, 0.963776052F, 0.966976464F, 0.970031261F, 0.972939968F,
    0.975702107F, 0.97831738F, 0.980785251F, 0.983105481F, 0.985277653F,
    0.987301409F, 0.989176512F, 0.990902662F, 0.992479563F, 0.993907F,
    0.99518472F, 0.996312618F, 0.997290432F, 0.998118103F, 0.99879545F,
    0.999322414F, 0.999698818F, 0.999924719F, 1.0F, 0.999924719F, 0.999698818F,
    0.999322414F, 0.99879545F, 0.998118103F, 0.997290432F, 0.996312618F,
    0.99518472F, 0.993907F, 0.992479563F, 0.990902662F, 0.989176512F,
    0.987301409F, 0.985277653F, 0.983105481F, 0.980785251F, 0.97831738F,
    0.975702107F, 0.972939968F, 0.970031261F, 0.966976464F, 0.963776052F,
    0.960430503F, 0.956940353F, 0.953306F, 0.949528158F, 0.945607305F,
    0.941544056F, 0.937339F, 0.932992816F, 0.928506076F, 0.923879504F,
    0.919113874F, 0.914209723F, 0.909167945F, 0.903989315F, 0.898674488F,
    0.893224299F, 0.887639642F, 0.881921232F, 0.876070082F, 0.870086968F,
    0.863972843F, 0.857728601F, 0.851355195F, 0.84485358F, 0.838224709F,
    0.831469595F, 0.824589252F, 0.817584813F, 0.81045717F, 0.803207517F,
    0.795836926F, 0.78834641F, 0.780737221F, 0.773010433F, 0.765167236F,
    0.757208824F, 0.749136388F, 0.740951121F, 0.732654274F, 0.724247098F,
    0.715730786F, 0.707106769F, 0.698376298F, 0.689540565F, 0.680601F, 0.671559F,
    0.662415802F, 0.653172851F, 0.643831551F, 0.634393334F, 0.624859512F,
    0.615231633F, 0.605511F, 0.59569931F, 0.585797906F, 0.575808227F,
    0.565731823F, 0.555570245F, 0.545325041F, 0.534997642F, 0.524589717F,
    0.514102757F, 0.50353837F, 0.492898226F, 0.482183754F, 0.471396744F,
    0.460538715F, 0.449611336F, 0.438616246F, 0.427555084F, 0.416429579F,
    0.40524134F, 0.393992066F, 0.382683456F, 0.371317208F, 0.359895051F,
    0.348418683F, 0.336889863F, 0.32531032F, 0.313681751F, 0.302005947F,
    0.290284663F, 0.27851969F, 0.266712785F, 0.254865676F, 0.242980197F,
    0.231058121F, 0.219101235F, 0.207111388F, 0.195090324F, 0.183039889F,
    0.170961902F, 0.15885815F, 0.146730468F, 0.134580716F, 0.122410677F,
    0.110222206F, 0.0980171412F, 0.0857973173F, 0.0735645667F, 0.0613207407F,
    0.0490676761F, 0.0368072242F, 0.024541229F, 0.0122715384F, 0.0F };

  int ihi;
  (void)Srate;
  for (nBd2 = 0; nBd2 < 200; nBd2++) {
    out[nBd2] = frame_in[nBd2];
    fv1[nBd2] = buffer[200 + nBd2];
    fv1[nBd2 + 200] = frame_in[nBd2];
  }

  memcpy(&buffer[0], &fv1[0], 400U * sizeof(float));

  /*  frame number counter */
  /*  frame number counter */
  /*  frame number counter */
  if (!noise_ps_not_empty) {
    noise_ps.size[0] = 1;
    noise_ps.size[1] = 512;
    memset(&noise_ps.data[0], 0, sizeof(float) << 9);
    noise_ps_not_empty = true;
  }

  if (!noise_ps_temp_not_empty) {
    nBd2 = noise_ps_temp->size[0] * noise_ps_temp->size[1];
    noise_ps_temp->size[0] = 1;
    noise_ps_temp->size[1] = 512;
    emxEnsureCapacity_real32_T(noise_ps_temp, nBd2);
    for (nBd2 = 0; nBd2 < 512; nBd2++) {
      noise_ps_temp->data[nBd2] = 0.0F;
    }

    noise_ps_temp_not_empty = true;
  }

  if (!G_prev_not_empty) {
    G_prev.size[0] = 1;
    G_prev.size[1] = 512;
    memset(&G_prev.data[0], 0, sizeof(float) << 9);
    G_prev_not_empty = true;
  }

  if (!posteri_prev_not_empty) {
    posteri_prev.size[0] = 1;
    posteri_prev.size[1] = 512;
    memset(&posteri_prev.data[0], 0, sizeof(float) << 9);
    posteri_prev_not_empty = true;
  }

  /*  fs = 8000; */
  /*  set parameter values */
  /*  smoothing factor in noise spectrum update */
  /*  smoothing factor in priori update */
  /*  VAD threshold */
  /*  L is frame length  */
  /*  hamming window */
  /*  U= ( hamming_win'* hamming_win)/ L; % normalization factor */
  /*  U2 = ( hamming(fft_len)'* hamming(fft_len))/ fft_len; */
  d0 = 0.0;
  for (nBd2 = 0; nBd2 < 400; nBd2++) {
    d0 += a[nBd2] * b[nBd2];
  }

  U2 = (float)d0 / 512.0F;

  /*  normalization factor */
  /*  SPL calculation */
  if (update == 1.0F) {
    for (nBd2 = 0; nBd2 < 400; nBd2++) {
      fv1[nBd2] = buffer[nBd2] * fv2[nBd2];
    }

    fft(fv1, fcv0);
    b_abs(fcv0, fv3);
    power(fv3, x);
    twid_re = x[0];
    for (k = 0; k < 399; k++) {
      twid_re += x[k + 1];
    }

    SPL = rt_roundf_snf(10.0F * (float)log10((float)sqrt(twid_re / 400.0F) /
      2.0E-5F + 1.0F));
    update = 2.0F;
  } else if ((update != 1.0F) && (update <= 999.0F)) {
    update++;
  } else {
    if (update == 1000.0F) {
      update = 1.0F;
    }
  }

  if (label > -1.0F) {
    if (SPL <= spl_threshold) {
      if (count == 1.0F) {
        memcpy(&out[0], &buffer[0], 200U * sizeof(float));
      } else {
        for (nBd2 = 0; nBd2 < 200; nBd2++) {
          out[nBd2] = overlap_spl[nBd2] + buffer[nBd2];
        }
      }

      /*  %       */
      memcpy(&overlap_spl[0], &buffer[200], 200U * sizeof(float));
      count++;

      /*        % changing L to fft_len */
      j = 1.0F;
      noise_ps.size[0] = 1;
      noise_ps.size[1] = 400;
      noise_ps_not_empty = true;
      G_prev.size[0] = 1;
      G_prev.size[1] = 400;
      G_prev_not_empty = true;
      posteri_prev.size[0] = 1;
      posteri_prev.size[1] = 400;
      memset(&noise_ps.data[0], 0, 400U * sizeof(float));
      memset(&G_prev.data[0], 0, 400U * sizeof(float));
      memset(&posteri_prev.data[0], 0, 400U * sizeof(float));
      posteri_prev_not_empty = true;
      memset(&overlap[0], 0, 200U * sizeof(float));
      nBd2 = noise_ps_temp->size[0] * noise_ps_temp->size[1];
      noise_ps_temp->size[0] = 1;
      noise_ps_temp->size[1] = 400;
      emxEnsureCapacity_real32_T(noise_ps_temp, nBd2);
      for (nBd2 = 0; nBd2 < 400; nBd2++) {
        noise_ps_temp->data[nBd2] = 0.0F;
      }

      noise_ps_temp_not_empty = true;
    } else {
      if ((j <= dl) && (label == 1.0F)) {
        for (nBd2 = 0; nBd2 < 400; nBd2++) {
          fv1[nBd2] = buffer[nBd2] * fv2[nBd2];
        }

        b_fft(fv1, noise_fft);
        for (k = 0; k < 512; k++) {
          twid_re = rt_hypotf_snf(noise_fft[k].re, noise_fft[k].im);
          noisy_ps[k] = twid_re * twid_re;
        }

        emxInit_real32_T(&r0, 2);
        twid_im = 512.0F * U2;
        snr_detect = temp - 1.0F;
        nBd2 = r0->size[0] * r0->size[1];
        r0->size[0] = 1;
        r0->size[1] = noise_ps.size[1];
        emxEnsureCapacity_real32_T(r0, nBd2);
        iy = noise_ps.size[1];
        for (nBd2 = 0; nBd2 < iy; nBd2++) {
          r0->data[r0->size[0] * nBd2] = noise_ps.data[noise_ps.size[0] * nBd2] *
            snr_detect;
        }

        noise_ps.size[0] = 1;
        noise_ps.size[1] = 512;
        for (nBd2 = 0; nBd2 < 512; nBd2++) {
          noise_ps.data[noise_ps.size[0] * nBd2] = (r0->data[nBd2] +
            noisy_ps[nBd2] / twid_im) / temp;
        }

        emxFree_real32_T(&r0);
        noise_ps_not_empty = true;
        noise_count++;
        temp = noise_count - 1.0F;
        flag = 1.0F;

        /*             noise_ps_temp = noise_ps/temp; */
      }

      if (!(flag == 0.0F)) {
        if (dec_count <= dl) {
          dec_count++;
        } else {
          for (nBd2 = 0; nBd2 < 400; nBd2++) {
            fv1[nBd2] = buffer[nBd2] * fv2[nBd2];
          }

          b_fft(fv1, noise_fft);
          twid_im = 512.0F * U2;
          for (k = 0; k < 512; k++) {
            twid_re = rt_hypotf_snf(noise_fft[k].re, noise_fft[k].im);
            noisy_ps[k] = twid_re * twid_re / twid_im;
          }

          if (first_count == 1.0F) {
            /*  initialize posteri */
            rdivide(noisy_ps, noise_ps_temp, posteri);
            for (i = 0; i < 512; i++) {
              snr_detect = posteri[i] - 1.0F;
              if (posteri[i] - 1.0F < 0.0F) {
                snr_detect = 0.0F;
              }

              snr_detect = 0.98F + 0.0199999809F * snr_detect;
              posteri_prime[i] = snr_detect;
            }

            /*          */
          } else {
            rdivide(noisy_ps, noise_ps_temp, posteri);
            for (i = 0; i < 512; i++) {
              snr_detect = posteri[i] - 1.0F;
              if (posteri[i] - 1.0F < 0.0F) {
                snr_detect = 0.0F;
              }

              posteri_prime[i] = snr_detect;
            }

            c_power(G_prev.data, G_prev.size, noisy_ps, b_size);
            for (nBd2 = 0; nBd2 < 512; nBd2++) {
              posteri_prime[nBd2] = 0.98F * noisy_ps[nBd2] *
                posteri_prev.data[nBd2] + 0.0199999809F * posteri_prime[nBd2];
            }
          }

          /*               log_sigma_k= posteri.* priori./ (1+ priori)- log(1+ priori);     */
          /*               vad_decision= sum( log_sigma_k)/ L;     */
          /*                   if (vad_decision< eta)  */
          /*                        % noise only frame found */
          /*                        noise_ps= mu* noise_ps+ (1- mu)* noisy_ps; */
          /*                        l = 1; */
          /*                        %vad( n_start: n_start+ L- 1)= 0; */
          /*                   else */
          /*                        l = 2; */
          /*                   end */
          /*               */
          /*      ===end of vad=== */
          for (nBd2 = 0; nBd2 < 512; nBd2++) {
            posteri_prime[nBd2] /= 1.0F + posteri_prime[nBd2];
          }

          b_sqrt(posteri_prime);

          /* EFFICIENT MUSICAL NOISE SUPPRESSION FOR SPEECH ENHANCEMENT SYSTEMS */
          /*  postfilter applied to the gain function */
          c_abs(noise_fft, noisy_ps);
          for (nBd2 = 0; nBd2 < 512; nBd2++) {
            b_posteri_prime[nBd2] = posteri_prime[nBd2] * noisy_ps[nBd2];
          }

          b_power(b_posteri_prime, noisy_ps);
          twid_re = noisy_ps[0];
          for (k = 0; k < 511; k++) {
            twid_re += noisy_ps[k + 1];
          }

          for (k = 0; k < 512; k++) {
            snr_detect = rt_hypotf_snf(noise_fft[k].re, noise_fft[k].im);
            noisy_ps[k] = snr_detect * snr_detect;
          }

          snr_detect = noisy_ps[0];
          for (k = 0; k < 511; k++) {
            snr_detect += noisy_ps[k + 1];
          }

          snr_detect = twid_re / (snr_detect + 1.0E-7F);
          if (snr_detect >= 0.4F) {
            snr_detect = 1.0F;
          }

          if (snr_detect == 1.0F) {
            snr_detect = 1.0F;
          } else {
            snr_detect = 2.0F * rt_roundf_snf((1.0F - snr_detect / 0.4F) * 40.0F)
              + 1.0F;
          }

          emxInit_real32_T(&wind, 2);

          /*  assert(N<256); */
          twid_im = 1.0F / snr_detect;
          nBd2 = wind->size[0] * wind->size[1];
          wind->size[0] = 1;
          wind->size[1] = (int)snr_detect;
          emxEnsureCapacity_real32_T(wind, nBd2);
          iy = (int)snr_detect;
          for (nBd2 = 0; nBd2 < iy; nBd2++) {
            wind->data[nBd2] = twid_im;
          }

          for (k = 0; k < 512; k++) {
            noisy_ps[k] = (float)fabs(posteri_prime[k]);
            posteri_prime[k] = 0.0F;
          }

          if (wind->size[1] > 0) {
            nBd2 = wind->size[1] >> 1;
            for (k = 1; k <= nBd2; k++) {
              iy = nBd2 - k;
              for (ix = 0; ix <= 510 - iy; ix++) {
                posteri_prime[ix] += wind->data[k - 1] * noisy_ps[(iy + ix) + 1];
              }
            }

            for (k = nBd2; k + 1 <= wind->size[1]; k++) {
              iy = k - nBd2;
              for (ix = 0; ix <= 511 - iy; ix++) {
                posteri_prime[iy + ix] += wind->data[k] * noisy_ps[ix];
              }
            }
          }

          emxFree_real32_T(&wind);

          /* end of postfilter */
          for (nBd2 = 0; nBd2 < 512; nBd2++) {
            noise_fft[nBd2].re *= posteri_prime[nBd2];
            noise_fft[nBd2].im *= posteri_prime[nBd2];
          }

          ix = 0;
          ju = 0;
          iy = 0;
          for (i = 0; i < 511; i++) {
            b_y1[iy] = noise_fft[ix];
            nBd2 = 512;
            tst = true;
            while (tst) {
              nBd2 >>= 1;
              ju ^= nBd2;
              tst = ((ju & nBd2) == 0);
            }

            iy = ju;
            ix++;
          }

          b_y1[iy] = noise_fft[ix];
          for (i = 0; i <= 511; i += 2) {
            snr_detect = b_y1[i + 1].re;
            U2 = b_y1[i + 1].im;
            b_y1[i + 1].re = b_y1[i].re - b_y1[i + 1].re;
            b_y1[i + 1].im = b_y1[i].im - b_y1[i + 1].im;
            b_y1[i].re += snr_detect;
            b_y1[i].im += U2;
          }

          iy = 2;
          nBd2 = 4;
          k = 128;
          ix = 509;
          while (k > 0) {
            for (i = 0; i < ix; i += nBd2) {
              snr_detect = b_y1[i + iy].re;
              U2 = b_y1[i + iy].im;
              b_y1[i + iy].re = b_y1[i].re - snr_detect;
              b_y1[i + iy].im = b_y1[i].im - U2;
              b_y1[i].re += snr_detect;
              b_y1[i].im += U2;
            }

            ju = 1;
            for (b_j = k; b_j < 256; b_j += k) {
              twid_re = fv0[b_j];
              twid_im = fv4[b_j];
              i = ju;
              ihi = ju + ix;
              while (i < ihi) {
                snr_detect = twid_re * b_y1[i + iy].re - twid_im * b_y1[i + iy].
                  im;
                U2 = twid_re * b_y1[i + iy].im + twid_im * b_y1[i + iy].re;
                b_y1[i + iy].re = b_y1[i].re - snr_detect;
                b_y1[i + iy].im = b_y1[i].im - U2;
                b_y1[i].re += snr_detect;
                b_y1[i].im += U2;
                i += nBd2;
              }

              ju++;
            }

            k /= 2;
            iy = nBd2;
            nBd2 += nBd2;
            ix -= iy;
          }

          for (nBd2 = 0; nBd2 < 512; nBd2++) {
            b_y1[nBd2].re *= 0.001953125F;
            b_y1[nBd2].im *= 0.001953125F;
            noisy_ps[nBd2] = b_y1[nBd2].re;
          }

          if (first_count == 1.0F) {
            memcpy(&out[0], &noisy_ps[0], 200U * sizeof(float));
          } else {
            for (nBd2 = 0; nBd2 < 200; nBd2++) {
              out[nBd2] = overlap[nBd2] + b_y1[nBd2].re;
            }
          }

          memcpy(&overlap[0], &noisy_ps[200], 200U * sizeof(float));
          G_prev.size[0] = 1;
          G_prev.size[1] = 512;
          G_prev_not_empty = true;
          posteri_prev.size[0] = 1;
          posteri_prev.size[1] = 512;
          memcpy(&G_prev.data[0], &posteri_prime[0], sizeof(float) << 9);
          memcpy(&posteri_prev.data[0], &posteri[0], sizeof(float) << 9);
          posteri_prev_not_empty = true;
        }
      }

      /*          if(j<decisionFrame) */
      /*              if(label==1) */
      /*               noise = buffer; */
      /*               noise = noise.* hamming_win'; */
      /*               noise_fft = fft( noise, fft_len); */
      /*               noise_ps = noise_ps + ( abs( noise_fft).^ 2)/ (fft_len* U2); */
      /*              end */
      /*          else */
      /*              j=1; */
      /*              noise_ps_temp = noise_ps; */
      /*          end */
      /*       if(j>=decisionFrame) */
      /*           noise_ps_temp = noise_ps/temp; */
      /*           noise_count = 1; */
      /*           j=0; */
      /*  % %         noise_ps = zeros(1, fft_len);  */
      /*       end */
      if (j == dl) {
        /*               if (first_count==1) */
        if (noise_count > 1.0F) {
          nBd2 = noise_ps_temp->size[0] * noise_ps_temp->size[1];
          noise_ps_temp->size[0] = 1;
          emxEnsureCapacity_real32_T(noise_ps_temp, nBd2);
          nBd2 = noise_ps_temp->size[0];
          iy = noise_ps_temp->size[1];
          iy *= nBd2;
          for (nBd2 = 0; nBd2 < iy; nBd2++) {
            noise_ps_temp->data[nBd2] = ((chunk_count - 1.0F) *
              noise_ps_temp->data[nBd2] + noise_ps.data[nBd2]) / chunk_count;
          }

          noise_ps_temp_not_empty = !(noise_ps_temp->size[1] == 0);

          /*                      noise_count = 1; */
          /*                      chunk_count = chunk_count+1; */
        }

        /*               else */
        /*                   noise_ps_temp = noise_ps_temp*mu+(1-mu)*noise_ps;  */
        /*               end */
        noise_count = 1.0F;
        chunk_count++;
        j = 0.0F;
      }

      if (flag == 1.0F) {
        j++;
        first_count = 2.0F;
      }

      /*       noise_level = sum(noise_ps_temp); */
      memset(&overlap_spl[0], 0, 200U * sizeof(float));
      count = 1.0F;
    }
  }
}

/*
 * Arguments    : void
 * Return Type  : void
 */
void wiener_ADAPTIVE_NE_free(void)
{
  emxFree_real32_T(&noise_ps_temp);
    flag = 0.0F;
}

/*
 * Arguments    : void
 * Return Type  : void
 */
void wiener_ADAPTIVE_NE_init(void)
{
  posteri_prev.size[1] = 0;
  G_prev.size[1] = 0;
  emxInit_real32_T(&noise_ps_temp, 2);
  noise_ps.size[1] = 0;
  posteri_prev_not_empty = false;
  G_prev_not_empty = false;
  noise_ps_temp_not_empty = false;
  noise_ps_not_empty = false;
  dec_count = 1.0F;
  chunk_count = 1.0F;
  temp = 1.0F;
  memset(&buffer[0], 0, 400U * sizeof(float));
  j = 1.0F;
  noise_count = 1.0F;
  count = 1.0F;
  first_count = 1.0F;
  memset(&overlap[0], 0, 200U * sizeof(float));
  memset(&overlap_spl[0], 0, 200U * sizeof(float));
  update = 1.0F;
  SPL = 37.0F;
  flag = 0.0F;
}

/*
 * File trailer for wiener_ADAPTIVE_NE.c
 *
 * [EOF]
 */
